﻿#region GNU GPL Version 3 License

/// Copyright 2013 Shailesh Lolam
/// 
/// This file Storage.cs is part of AzEzAuto.
/// 
/// AzEzAuto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
/// 
/// AzEzAuto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
/// 
/// You should have received a copy of the GNU General Public License along with AzEzAuto. If not, see http://www.gnu.org/licenses/.
/// 
/// History:
/// ______________________________________________________________
/// Created         04-2013             Shailesh Lolam

#endregion
      
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AzEzAuto.Entities;
using System.Security.Cryptography.X509Certificates;
using AzEzAuto.Utils;
using System.Collections.Specialized;
using AzEzAuto.Entities.Storage;

namespace AzEzAuto.Management
{
    public class Storage : Base
    {
        public Storage(HttpApi httpApi)
            :base(httpApi)
        {
        }

        public Storage(HttpApi httpApi, string version)
            : base(httpApi, version)
        {
        }

        public string CreateHostedService(string subscriptionId, CreateStorageService css)
        {
            Guard.ArgumentNull(css, "css");
            Guard.CheckSubscriptionId(subscriptionId);
            NameValueCollection headers = new NameValueCollection();
            headers[VERSION_TAG] = _version;
            _httpApi.Post(new Uri(string.Format("https://management.core.windows.net/{0}/services/storageservices", subscriptionId)), "POST", css, headers);
            return headers[REQUEST_ID];
        }
        public string DeleteStorageService(string subscriptionId, string serviceName)
        {
            Guard.ArgumentNullOrEmpty(serviceName, "serviceName");
            Guard.CheckSubscriptionId(subscriptionId);
            NameValueCollection headers = new NameValueCollection();
            headers[VERSION_TAG] = _version;
            _httpApi.Post(new Uri(string.Format("https://management.core.windows.net/{0}/services/storageservices/{1}", subscriptionId, serviceName)), "DELETE", null, headers);
            return headers[REQUEST_ID];
        }
        public string UpdateStorageService(string subscriptionId, UpdateStorageService uss, string serviceName)
        {
            Guard.ArgumentNull(uss, "uss");
            Guard.CheckSubscriptionId(subscriptionId);
            NameValueCollection headers = new NameValueCollection();
            headers[VERSION_TAG] = _version;
            _httpApi.Post(new Uri(string.Format("https://management.core.windows.net/{0}/services/storageservices/{1}", subscriptionId, serviceName)), "PUT", uss, headers);
            return headers[REQUEST_ID];
        }

        public StorageService RegenerateKeys(string subscriptionId, string serviceName, RegenerateKeys rk)
        {
            Guard.ArgumentNull(rk, "rk");
            Guard.ArgumentNullOrEmpty(serviceName, "serviceName");
            Guard.CheckSubscriptionId(subscriptionId);
            NameValueCollection headers = new NameValueCollection();
            headers[VERSION_TAG] = _version;
            return _httpApi.Post<StorageService>(new Uri(string.Format("https://management.core.windows.net/{0}/services/storageservices/{1}/keys?action=regenerate", subscriptionId, serviceName)), "POST", rk, headers);
        }

        public StorageService GetStorageKeys(string subscriptionId, string serviceName)
        {
            Guard.ArgumentNullOrEmpty(serviceName, "serviceName");
            Guard.CheckSubscriptionId(subscriptionId);
            NameValueCollection headers = new NameValueCollection();
            headers[VERSION_TAG] = _version;
            return _httpApi.Get<StorageService>(new Uri(string.Format("https://management.core.windows.net/{0}/services/storageservices/{1}/keys", subscriptionId, serviceName)),  headers);
        }
    }
}
